<?php
require_once ROOT_LIBRARY_UTILITY.DS. 'BaseController.php';
require_once ROOT_LIBRARY_UTILITY.DS. 'Globals.php';

require_once ROOT_APPLICATION_MODULE_BACKEND_MODELS.DS. 'Model_Solution.php';
require_once ROOT_APPLICATION_MODULE_BACKEND_MODELS.DS. 'Model_Service_Type.php';
require_once ROOT_APPLICATION_MODULE_BACKEND_MODELS.DS. 'Model_Customer.php';

class SolutionController extends BaseController{

	public function init(){
		parent::init();

	}

	public function indexAction(){
        try
        {
            $type = $this->_request->getParam("type");
            if($this->_request->getMethod() == "POST")
            {

            }
            else
            {
                $view = new Zend_View();
                $view->setScriptPath(ROOT_APPLICATION_MODULE_DEFAULT_VIEWS.DS.'scripts'.DS);
                $mdSolution = new Model_Solution();
                $mdServiceType = new Model_Service_Type();

                $serviceType = $mdServiceType->_getByKey($type);
                $serviceTypeList = $mdServiceType->_getAll();

                if($type == IID)
                {
                    $view->solutionList = $mdSolution->getByServiceType($type);
                    $view->serviceType = $serviceType;
                    $view->serviceTypeList = $serviceTypeList;
                    $view->serviceTypeId = $type;
                    echo $view->render('solution/iid.phtml');
                }
                else
                {
                    $view->serviceType = $serviceType;
                    $view->serviceTypeList = $serviceTypeList;
                    $view->serviceTypeId = $type;
                    $serviceType = $mdServiceType->_getAll(" parent_id = $type");

                    $listId = array();
                    $data = array();
                    foreach ($serviceType as $key => $item)
                        $listId[] = $item->id;

                    array_multisort($serviceType, SORT_DESC, $listId);
                    $serviceType = array_slice($serviceType, 0, 4);

                    foreach ($serviceType as $key => $item)
                    {
                        $data[$key] = $mdSolution->getByServiceType($item->id);
                    }
                    $view->listSolutions = $data;
                    $view->solutionServiceType = $serviceType;

                    echo $view->render('solution/osd.phtml');
                }
            }
        }
        catch(Exception $ex)
        {

        }
	}

    public function detailAction()
    {
        try
        {

        }
        catch(Exception $ex)
        {

        }
    }
}